#include"verilated.h"
#include"obj_dir/Vtop.h"
#include"stdio.h"
#include"stdlib.h"
#include"assert.h"
#include"verilated_vcd_c.h"
#include"../../nvboard/nvboard.h"
VerilatedContext* contextp = NULL;
VerilatedVcdC* tfp = NULL;

static TOP_NAME dut;
static Vtop* top;
void nvboard_bind_all_pins(Vtop* top);

void step_and_dump_wave(){
	nvboard_update();
	top->eval();
	contextp->timeInc(1);
	tfp->dump(contextp->time());
}


void sim_init(){
	nvboard_init();
	contextp = new VerilatedContext;
	top = new Vtop;
	tfp = new VerilatedVcdC;
	contextp->traceEverOn(true);
	top->trace(tfp,0);
	tfp->open("obj_dir/top.vcd");
}

void sim_exit(){
	step_and_dump_wave();
	tfp->close();
}



int main(){
	nvboard_bind_all_pin(&dut);
	sim_init();
	while(!contextp->gotFinish()){
		int a = rand() & 1;
		int b = rand() & 1;
		top->a = a;
		top->b = b;
		step_and_dump_wave();
		printf("a=%d ,b=%d,f=%d\n",a,b,top->f);
		assert(top->f == a ^ b);}
	delete top;
	delete contextp;
	nvboard_quit();
}

